﻿<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>Deferred</title>
    <script src="../jquery-2.0.3.js"></script>

</head>
<body>
<script>
    //先2  后1
    //(function () {
    //    setTimeout(function() {
    //        alert(1);
    //    }, 1000);
    //    alert(2);

    //})();

    //先1  后2
    (function () {
        var dfd = $.Deferred();
        setTimeout(function () {
            alert(1);
            dfd.resolve();
        }, 1000);
        dfd.done(function() {
            alert(2);
        });
    })();



</script>

</body>
</html>